/**
 * 
 */
package com.google.code.netz.wfe.events;

import static com.google.code.netz.wfe.events.CaseEvent.CaseEventType.CASE_CLOSED;
import static com.google.code.netz.wfe.events.CaseEvent.CaseEventType.CASE_OPENED;
import static com.google.code.netz.wfe.events.CaseEvent.CaseEventType.CASE_SUBMITTED;

import netz.test.signup.UserData;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.code.netz.wfe.model.ICase;
import com.google.code.netz.wfe.model.IToken;
import com.google.code.netz.wfe.model.Place;

/**
 * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
 * @since 1.0
 * @version $Id: CaseEventListener.java 19 2009-02-22 15:13:24Z rahul.thakur.xdev $
 */
public class CaseEventListener implements ITypedEventListener<CaseEvent<ICase<?>>> {

	/**
	 * Commons logging.
	 */
	private static Log log = LogFactory.getLog(CaseEventListener.class);

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.google.code.netz.wfe.events.ITypedEventListener#onEvent(com.google.code.netz.wfe.events.TypedEvent)
	 */
	@Override
	public void onEvent(CaseEvent<ICase<?>> event) {
		if (event.getType() == CASE_SUBMITTED) {
			handleCaseSubmittedEvent(event);
		} else if (event.getType() == CASE_CLOSED) {
			handleCaseClosedEvent(event);
		} else if (event.getType() == CASE_OPENED) {
			handleCaseOpenedEvent(event);
		}
	}

	/**
	 * 
	 * @param event
	 */
	private void handleCaseOpenedEvent(CaseEvent<ICase<?>> event) {
		// TODO Auto-generated method stub
		log.info("Handling event: " + event.getType().asString());
	}

	/**
	 * 
	 * @param event
	 */
	private void handleCaseClosedEvent(CaseEvent<ICase<?>> event) {
		// TODO Auto-generated method stub
		log.info("Handling event: " + event.getType().asString());
	}

	/**
	 * 
	 * @param event
	 */
	private void handleCaseSubmittedEvent(CaseEvent<ICase<?>> event) {
		log.info("Handling event: " + event.getType().asString());
		ICase<?> kase = event.getSource();

		Place<?> source = kase.getSource();
		source.addToken(new IToken<?>() {
			@Override
			public Object getData() {
				return new UserData();
			}
		});
	}

}
